//
//  WLFileTransportHeadModel.m
//  WanLian
//
//  Created by 123456 on 2019/1/4.
//  Copyright © 2019 wanlian. All rights reserved.
//

#import "WLFileTransportHeadModel.h"

//#define SEND_SIZE    65536           //64K
//#define SEND_SIZE    32768           //32K
//#define SEND_SIZE    131072            //128K
#define SEND_SIZE    262144            //256K

@implementation WLFileTransportHeadModel

+ (instancetype)createWithTaskModel:(WLFileRequest *)model index:(int)index sourceId:(int)sourceId {
    WLFileTransportHeadModel *blockModel = [[WLFileTransportHeadModel alloc] init];
    blockModel.blockSizeUnit = model.blockSize;
    blockModel.currentSize = model.currentSize;
    blockModel.sendSizeUnit = SEND_SIZE;
    blockModel.blockIndex = index;
    long realBlockSize = model.blockSize;
    if (index == model.blockCount - 1 && model.p_last_bs > 0) {
        realBlockSize = model.p_last_bs;
    }
    blockModel.bs = realBlockSize;
    int num = (int)blockModel.bs / blockModel.sendSizeUnit;
    if (blockModel.bs % blockModel.sendSizeUnit == 0) {
        blockModel.totalNum = num;
    } else {
        blockModel.totalNum = num + 1;
    }
    blockModel.fileURL = model.fileURL;
    blockModel.mediaLocalURL = model.mediaLocalURL;
    blockModel.freeid = sourceId;
    return blockModel;
    
}
@end
